package com.jian.java;

import com.jian.java.bean.Person;
import com.jian.java.bean.User;
import com.jian.java.config.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.http.converter.StringHttpMessageConverter;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * @author Jiange
 * @create 2021-04-26-13:55
 */
//这个注解表示这是一个springboot应用  表示主程序类
@SpringBootApplication()
public class MainApp {
    public static void main(String[] args) {
        //返回IOC容器
        ConfigurableApplicationContext run = SpringApplication.run(MainApp.class, args);
        MyConfig myConfig = run.getBean("myConfig", MyConfig.class);
        User user = myConfig.user();
        User user1 = myConfig.user();
        System.out.println("====");
        System.out.println(user == user1);
        String[] beanNamesForType = run.getBeanNamesForType(User.class);
        String[] beanNamesForType1 = run.getBeanNamesForType(Person.class);
        System.out.println(beanNamesForType1.length);
        for (int i = 0; i < beanNamesForType1.length; i++) {
            System.out.println(beanNamesForType1[i]);
        }
        Stream<String> stream = Arrays.stream(beanNamesForType);
        stream.forEach(System.out::println);

        StringHttpMessageConverter stringHttpMessageConverter = run.getBean("stringHttpMessageConverter", StringHttpMessageConverter.class);
        System.out.println(stringHttpMessageConverter);
    }
}
